import threading
import time
from datetime import timedelta, date, datetime
import do
import os


def go(id, pwd, seat, st, ed):
    while True:
        now = datetime.now().minute
        nowh = datetime.now().hour
        print(str(id) + ' wait ' +str(now)+ ' hour ' +str(nowh))
        if now == 0 and nowh == 0:
            time.sleep(3)
            for i in range(50):
                res = do.start_subscribe(id, pwd, seat, st, ed)
                print(res['msg'])
                time.sleep(0.5)
                if '当前时间预约冲突' in res['msg'] or '操作成功' in res['msg']:
                    return
        time.sleep(0.5)


# id, pwd, seat, st, ed, stt, edt
if __name__ == '__main__':
    tomorrow = (date.today() + timedelta(days=2)).strftime("%Y-%m-%d")
    # tomorrow1 = (date.today() + timedelta(days=1)).strftime("%Y-%m-%d")
    t1 = threading.Thread(target=go,
                          args=(
                              '172100530', '212430', '100460082',
                              tomorrow + ' 8:00', tomorrow + ' 12:00',
                              ))
    t2 = threading.Thread(target=go,
                          args=(
                              '172020926', '080323', '100460084',
                              tomorrow + ' 8:00', tomorrow + ' 12:00',
                              ))
    t3 = threading.Thread(target=go,
                          args=(
                              '172100527', '206911', '100460084',
                              tomorrow + ' 15:00', tomorrow + ' 19:00',
                              ))
    t4 = threading.Thread(target=go,
                          args=(
                              '172100534', '151813', '100460082',
                              tomorrow + ' 15:00', tomorrow + ' 19:00',
                              ))
    t5 = threading.Thread(target=go,
                          args=(
                              '172100534', '151813', '100460082',
                              tomorrow1 + ' 15:00', tomorrow1 + ' 19:00',
                              ))

    


    t1.start()
    t2.start()
    t3.start()
    t4.start()
    # t5.start()
    

    
